import argparse
import os.path

import command


def cp():
    parser = argparse.ArgumentParser(description='复制文件或文件夹')
    parser.add_argument('-s', '--source', nargs='?', default='', help='源文件或文件夹路径(被复制)')
    parser.add_argument('-t', '--target', nargs='?', default='', help='源文件或文件夹路径(复制到的位置)')
    args, unknown_args = parser.parse_known_args()
    source = args.source
    target = args.target
    if len(unknown_args) == 1:
        source = unknown_args[0] if args.source == '' else args.source
        target = unknown_args[0] if args.target == '' and args.source != '' else args.target

    if len(unknown_args) == 2:
        source = unknown_args[0] if args.source == '' else args.source
        target = unknown_args[1] if args.target == '' else args.target
    if os.path.isfile(source):
        command_line = f"xcopy {source} {target} /I /H"
    else:
        command_line = f"xcopy {source} {target} /I /E /H"
    command.exe_command(command_line)


if __name__ == '__main__':
    cp()
